{% extends "admin/base_site.html" %}
{% load i18n admin_static admin_modify bootstrapped_goodies_tags mytags info_filters my_admin_tags %}
{% load url from future %}
{% load admin_urls %}

{% block extrahead %}{{ block.super }}
    {% url 'admin:jsi18n' as jsi18nurl %}
    <script type="text/javascript" src="{{ jsi18nurl|default:"../../../jsi18n/" }}"></script>
    <script type="text/javascript" src="{{ STATIC_URL }}js/jquery.popupwindow.js"></script>
    {{ media }}
{% endblock %}

{% block extrastyle %}{{ block.super }}
    <link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}"/>{% endblock %}

{% block coltype %}{% if ordered_objects %}colMS{% else %}colM{% endif %}{% endblock %}

{% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} change-form{% endblock %}

{% if not is_popup %}
    {% block breadcrumbs %}
        <ul class="breadcrumb">
            <li><a href="{% url 'admin:index' %}">{% trans 'Home' %}</a> <span class="divider">/</span></li>
            <li><a href="{% url 'admin:app_list' app_label=opts.app_label %}">{{ app_label|capfirst|escape }}</a> <span
                    class="divider">/</span></li>
            <li>{% if has_change_permission %}
                <a href="{% url opts|admin_urlname:'changelist' %}">{{ opts.verbose_name_plural|capfirst }}</a>{% else %}
                {{ opts.verbose_name_plural|capfirst }}{% endif %} <span class="divider">/</span></li>
            <li>{% if add %}{% trans 'Add' %} {{ opts.verbose_name }}{% else %}
                {{ original|truncatewords:"18" }}{% endif %}</li>
        </ul>
    {% endblock %}
{% endif %}

{% block object-tools %}
    {% if change %}{% if not is_popup %}
        <div class="pull-right">
            {% block object-tools-items %}
                <a href="history/" class="btn btn-inverse historylink">{% trans "History" %}</a>
                {% if has_absolute_url %}<a href="../../../r/{{ content_type_id }}/{{ object_id }}/"
                                            class="btn viewsitelink">{% trans "View on site" %}</a>{% endif %}
            {% endblock %}
        </div>
    {% endif %}{% endif %}
{% endblock %}

{% block content %}

    <script type="text/javascript">
        $(function () {
            $(".popupwindow").popupwindow();
        });
    </script>
    {% if object_id %}
        <div class="panel panel-default" style="border: 0">
            <a href="{% url 'sms_list' object_id %}" class="btn btn-primary btn-lg popupwindow"
               rel="center:1,width:1400,height:900,scrollbars:1">Manage</a>
        </div>
    {% endif %}
    {% with module_name=opts.module_name|lower|slugify %}
        {% render_with_template_if_exist opts.app_label|lower|add:"/admin_model_"|add:module_name|add:"_change_form.html" "" %}
    {% endwith %}

    {% hascrashreport uniq_id as has_cr %}
    {% if has_cr %}
        <div class="panel panel-warning">
            <div class="panel-heading">
                <h3 class="panel-title">Crash report(s) available</h3>
            </div>
            {% show_reports uniq_id %}
        </div>
    {% endif %}
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title">Additional data</h3>
        </div>
        <div class="panel-body">
            <ul class="list-group">
                {% for d in extras %}
                    <li class="list-group-item">
                        <p class="label label-default">{{ d.title|upper }}</p><br>
                        {% if d.title == 'card information' %}
                            <div class="well well-sm">{{ d.records|print_card_info_full }}</div>
                        {% endif %}
                        {{ d.records|form_print }}
                    </li>
                {% endfor %}
            </ul>
        </div>
    </div>


    <form class="form-horizontal"
          {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post"
          id="{{ opts.module_name }}_form">{% csrf_token %}{% block form_top %}{% endblock %}
        <div class="alert alert-warning">{% blocktrans %}Fields in <strong>bold</strong> are
            required.{% endblocktrans %}</div>
        {% if errors %}
            <div class="alert alert-error">
                {% blocktrans count counter=errors|length %}Please correct the error below.{% plural %}Please correct
                    the errors below.{% endblocktrans %}
                {{ adminform.form.non_field_errors }}
            </div>
        {% endif %}
        <div class="row-fluid">
            {% if save_on_top %}{% block submit_buttons_top %}{% submit_row %}{% endblock %}{% endif %}
        </div>
        <div class="row-fluid">
            <div id="content-main" class="span12">
                <div>
                    {% if is_popup %}<input type="hidden" name="_popup" value="1"/>{% endif %}

                    {% block field_sets %}
                        {% for fieldset in adminform %}
                            {% include "admin/includes/fieldset.html" %}
                        {% endfor %}
                    {% endblock %}

                    {% block after_field_sets %}{% endblock %}

                    {% block inline_field_sets %}
                        {% for inline_admin_formset in inline_admin_formsets %}
                            {% include inline_admin_formset.opts.template %}
                        {% endfor %}
                    {% endblock %}

                    {% block after_related_objects %}{% endblock %}

                    {% if adminform and add %}
                        <script type="text/javascript">document.getElementById("{{ adminform.first_field.id_for_label }}").focus();</script>
                    {% endif %}

                    {# JavaScript for prepopulated fields #}
                    {% prepopulated_fields_js %}

                </div>
            </div>
        </div>
        <div class="row-fluid">
            <div class="form-actions">
                {% block submit_buttons_bottom %}{% submit_row %}{% endblock %}
            </div>
        </div>
    </form>

{% endblock %}
